package cn.kai.test;

import cn.kai.baice.BaseTest;
import cn.kai.pet.domain.Pet;
import cn.kai.pet.domain.PetDetail;
import cn.kai.pet.service.IPetDetailService;
import cn.kai.pet.service.IPetService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;

public class CreateDateBase extends BaseTest {

    @Autowired
    private IPetService petService;

    @Autowired
    private IPetDetailService petDetailService;

    @Test
    public void initDataTest() throws Exception{
        // 以数据库中宠物/宠物详情第一条数据为例，进行数据伪造
        Long petId = 1L;
        Pet pet = petService.findById(petId);
        PetDetail petDetail = petDetailService.findByPetId(pet.getId());

        pet.setId(null);
        petDetail.setId(null);
        pet.setPetDetail(petDetail);

        for (int i = 0; i < 66; i++) {
            if (i%3==0){
                pet.setName("柯基"+i);
                pet.setCostprice("30");
                pet.setSaleprice(new BigDecimal(50));
            }
            else if(i%3==1){
                pet.setName("二哈"+i);
                pet.setCostprice("50");
                pet.setSaleprice(new BigDecimal(80));
            }
            else{
                pet.setName("金毛"+i);
                pet.setCostprice("100");
                pet.setSaleprice(new BigDecimal(150));
            }
            petService.add(pet);
        }
    }
}
